<?php
namespace app\tuchuang\loglic;

class Install
{
    //MYSQL版一键安装回调
    public function mysql()
    {
        //安装用户插件
        \daicuo\Apply::install('user','install');
        
        //安装附件插件
        \daicuo\Apply::install('attachment','install');
        
        //配置图床插件
        \daicuo\Apply::install('tuchuang','install');
        
        //MYSQL回调
        $this->mysqlBack();
        
        return true;
    }
    
    //mysqlInstall
    private function mysqlBack()
    {
        //公共
        \daicuo\Op::write([
            'site_name'  => '呆错图床系统',
            'url_suffix' => '.html',
        ], 'common', 'config', 'system', 0, 'yes');
        //首页
        return model('common/Route','loglic')->index('tuchuang/index/index', 'tuchuang');
    }
    
    //配置
    public function config()
    {
        config('common.validate_name', false);
        
        return model('common/Config','loglic')->install([
            'site_name'       => '呆错免费图床',
            'site_title'      => '呆错图床系统',
            'site_keywords'   => '免费图床程序,专业图片外链,免费图床API',
            'site_description'=> '呆错图床系统是一款免费的PHP图床程序，核心功能是提供图片外链服务、图床API服务、图片CDN加速与破解防盗链。',
            'theme'           => 'default',
            'theme_wap'       => 'default',
            'link_default'    => 'https://cdn.daicuo.cc/images/gzh/dc_01.jpg',
            'link_encode'     => 'imgDesEncode',
            'link_decode'     => 'imgDesDecode',
            'des_length'      => 86400,
            'cache_time'      => 0,
            'parse_action'    => 'daicuo',
        ],'tuchuang');
    }
    
    //伪静态
    public function route()
    {
        return true;
    }
    
    //权限
    public function auth()
    {
        //取消验证
        config('common.validate_name', false);
        
        //权限节点
        $caps = [
            'tuchuang/apis/change',
            'tuchuang/apis/parse',
            'tuchuang/apis/upload',
        ];
        
        //默认数据
        $default = [
            'op_name'       => 'vip',
            'op_module'     => 'tuchuang',
            'op_controll'   => 'auth',
            'op_action'     => 'front',
        ];
        
        //批量添加数据
        $dataList = [];
        foreach($caps as $key=>$value){
            array_push($dataList, DcArrayArgs(['op_value'=>$value],$default));
        }

        //调用接口
        return model('common/Auth','loglic')->install($dataList);
    }
    
    //字段
    public function field()
    {
        return true;
    }
    
    //后台菜单
    public function menu()
    {
        //后台一级菜单
        model('common/Menu','loglic')->install([
            [
                'term_name'   => '图床',
                'term_slug'   => 'tuchuang',
                'term_info'   => 'fa-image',
                'term_module' => 'tuchuang',
                'term_order'  => 9,
            ],
        ]);
        
        //后台二级菜单
        model('common/Menu','loglic')->install([
            [
                'term_name'   => '菜单管理',
                'term_slug'   => 'admin/navs/index?parent=tuchuang&navs_module=tuchuang',
                'term_info'   => 'fa-sitemap',
                'term_module' => 'tuchuang',
                'term_order'  => 4,
            ],
            [
                'term_name'   => '路由管理',
                'term_slug'   => 'admin/route/index?parent=tuchuang&op_module=tuchuang',
                'term_info'   => 'fa-wifi',
                'term_module' => 'tuchuang',
                'term_order'  => 3,
            ],
            [
                'term_name'   => '后台菜单',
                'term_slug'   => 'admin/menu/index?parent=tuchuang&term_module=tuchuang',
                'term_info'   => 'fa-navicon',
                'term_module' => 'tuchuang',
                'term_order'  => 2,
            ],
            [
                'term_name'   => '图床设置',
                'term_slug'   => 'tuchuang/admin/index',
                'term_info'   => 'fa-gear',
                'term_module' => 'tuchuang',
                'term_order'  => 1,
            ],
        ],'图床');
        
        return true;
    }
    
    //前台导航
    public function navs()
    {
        return model('common/Navs','loglic')->install([
            //导航栏
            [
                'navs_name'       => '图床首页',
                'navs_url'        => 'tuchuang/index/index',
                'navs_status'     => 'normal',
                'navs_type'       => 'navbar',
                'navs_action'     => 'index',
                'navs_module'     => 'tuchuang',
                'navs_active'     => 'tuchuangindex',
                'navs_target'     => '_self',
                'navs_order'      => 9,
            ],
            [
                'navs_name'       => '图床文档',
                'navs_url'        => 'https://www.daicuo.org/product/tuchuang/help',
                'navs_status'     => 'normal',
                'navs_type'       => 'navbar',
                'navs_action'     => 'index',
                'navs_module'     => 'tuchuang',
                'navs_active'     => 'tuchuanghelp',
                'navs_target'     => '_blank',
                'navs_order'      => 8,
            ],
            //侧边栏
            [
                'navs_type'       => 'sitebar',
                'navs_name'       => '我的图片',
                'navs_info'       => '我的图床',
                'navs_url'        => 'tuchuang/user/index',
                'navs_status'     => 'private',
                'navs_action'     => 'index',
                'navs_module'     => 'tuchuang',
                'navs_active'     => 'tuchuanguserindex',
                'navs_target'     => '_self',
                'navs_order'      => 9,
                'navs_parent'     => 0,
            ],
        ]);
    }
}